package com.example.shop_2210.search

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.base.entity.GoodsEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch
import retrofit2.http.Query

class SearchViewModel : BaseViewModel() {
    val searchSuccess = MutableLiveData<GoodsEntityResult>()
    val searchFail = MutableLiveData<String>()
    fun search(
        cid: Int,
        keyword: String,
        limit: Int,
        news: Boolean,
        page: Int,
        priceOrder: String,
        salesOrder: String
    ) {
        viewModelScope.launch {
            try {
                searchSuccess.value =
                    apiService.search(cid, keyword, limit, news, page, priceOrder, salesOrder)
            } catch (e: Exception) {
                searchFail.value = e.message
            }
        }
    }
}